package cc.eddic.practice.concurrency;



import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.Collection;


@Slf4j
@SpringBootApplication
public class ConcurrencyCxmApplication implements CommandLineRunner {
    public static void main(String[] args) {
        SpringApplication.run(ConcurrencyCxmApplication.
                class,args);
    }

    @Override
    public void run(String... args){
        long start=System.currentTimeMillis();
        if(log.isInfoEnabled()) log.info("Hello World");
        val folder="D:\\nginx-logs";
        val logItems=logParser.parse(folder);

        if(log.isInfoEnabled()){
            log.debug("{}",System.currentTimeMillis()-start);
            log.debug("{}",logItems.values().stream()
                    .mapToLong(Collection::size)
                    .sum());
            log.debug("{}",logItems.values().stream()
                    .flatMap(Collection::stream)
                    .filter(LogItem::isValidRequest)
                    .count());

        }
    }

    public ConcurrencyCxmApplication(@Qualifier("LogParserWithFutureCxmImpl") LogParser logParser){
        this.logParser=logParser;
   }

    private final LogParser logParser;
}
